//  src/utils/request.ts
import axios, { InternalAxiosRequestConfig, AxiosResponse } from 'axios'

// 创建 axios 实例
const service = axios.create({
  timeout: 500000,
  headers: {
    'Content-Type': 'application/json;charset=utf-8',
    'X-Requested-With': 'XMLHttpRequest',
    Accept: 'application/json',
    Credentials: 'include'
  },
  withCredentials: true
})

// 请求拦截器
service.interceptors.request.use(
  (config: InternalAxiosRequestConfig) => {
    // if (token) {
    //   config.headers['koala-token'] = token
    // }
    return config
  },
  (error: any) => {
    return Promise.reject(error)
  }
)

// 响应拦截器
service.interceptors.response.use(
  (response: AxiosResponse) => {
    // const { code } = response.data
    return response.data
  },
  (error: any) => {
    return Promise.reject(error.message)
  }
)

// 导出 axios 实例
export default service
